home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1257 / convio.c_ / convio.c
C/C++ Source or Header  |  1997-04-18  |  3KB  |  153 lines

  1. /* EasyCODE(C++) V5.1 02.03.1995 13:56:52 */
  2. /* EasyCODE O
  3. If=horizontal
  4. LevelNumbers=no
  5. LineNumbers=no
  6. ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
  7. PrinterFont=Courier New,,90,17414,-38,0,400,0,0,0,0,0,0,3,2,1,49
  8. LastLevelId=15 */
  9.  
  10. /* EasyCODE ( 1
  11.    convio.c */
  12.  
  13. /* EasyCODE ( 8
  14.    Include */
  15. #include "convio.h"
  16. /* EasyCODE ) */
  17.  
  18. /* EasyCODE ( 9
  19.    ReadLine */
  20.  
  21. /* EasyCODE F */
  22. BOOL ReadLine( char* inbuf, FILE* stream)
  23.  
  24. // Reads line from input file into buffer;
  25. // Returns FALSE at EOF.
  26.    {
  27.    if (fgets(inbuf,I_BUFSIZE,stream) == NULL)
  28.       {
  29.       if (feof(stream))
  30.          {
  31.          return (TRUE);
  32.          }
  33.       else
  34.          {
  35.          perror("ReadLine error");
  36.          exit(1);
  37.          }
  38.       }
  39.    else
  40.       {
  41.       return (FALSE);
  42.       }
  43.    }
  44. /* EasyCODE ) */
  45.  
  46. /* EasyCODE ( 10
  47.    StoreLine */
  48.  
  49. /* EasyCODE F */
  50. void StoreLine( char* outbuf, FILE* stream)
  51.  
  52. // Write line from buffer to output file
  53.    {
  54.    if (fputs(outbuf,stream) == EOF)
  55.       {
  56.       perror("WriteLine error");
  57.       exit(1);
  58.       }
  59.    }
  60. /* EasyCODE ) */
  61.  
  62. /* EasyCODE ( 11
  63.    OpenInput */
  64.  
  65. /* EasyCODE F */
  66. FILE* OpenInput( char* name)
  67.  
  68. // Opens file for reading
  69.    {
  70.    FILE * stream;
  71.    if ((stream = fopen(name, "r")) == NULL)
  72.       {
  73.       perror("fopen failed on input file");
  74.       exit(1);
  75.       }
  76.    else
  77.       {
  78.       return (stream);
  79.       }
  80.    }
  81. /* EasyCODE ) */
  82.  
  83. /* EasyCODE ( 12
  84.    TellPos */
  85.  
  86. /* EasyCODE F */
  87. long TellPos(FILE* stream)
  88.  
  89. // Delivers actual position of file pointer
  90.    {
  91.    long position;
  92.    if ((position = ftell(stream)) == -1)
  93.       {
  94.       perror("TellPos error");
  95.       exit(1);
  96.       }
  97.    else
  98.       {
  99.       return (position);
  100.       }
  101.    }
  102. /* EasyCODE ) */
  103.  
  104. /* EasyCODE ( 13
  105.    SeekPos */
  106.  
  107. /* EasyCODE F */
  108. void SeekPos(long position, FILE* stream)
  109.  
  110. // Sets file pointer to given position
  111.    {
  112.    if (fseek(stream,position,0) == -1)
  113.       {
  114.       perror("SeekPos error");
  115.       exit(1);
  116.       }
  117.    }
  118. /* EasyCODE ) */
  119.  
  120. /* EasyCODE ( 14
  121.    OpenOutput */
  122.  
  123. /* EasyCODE F */
  124. FILE* OpenOutput( char* name)
  125.  
  126. // Opens file for writing
  127.    {
  128.    FILE * stream;
  129.    if ((stream = fopen(name, "w")) == NULL)
  130.       {
  131.       perror("fopen failed on output file");
  132.       exit(1);
  133.       }
  134.    else
  135.       {
  136.       return (stream);
  137.       }
  138.    }
  139. /* EasyCODE ) */
  140.  
  141. /* EasyCODE ( 15
  142.    CloseFile */
  143.  
  144. /* EasyCODE F */
  145. void CloseFile(FILE* stream)
  146.  
  147. // Closes file
  148.    {
  149.    fclose(stream);
  150.    }
  151. /* EasyCODE ) */
  152. /* EasyCODE ) */
  153.